package ar.rhok.yerbus.core.services.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ar.rhok.yerbus.core.dao.TwitterAccountDAO;
import ar.rhok.yerbus.core.dao.UserDAO;
import ar.rhok.yerbus.core.domain.TweeterAccount;
import ar.rhok.yerbus.core.domain.User;
import ar.rhok.yerbus.core.services.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDAO userDAO;
	@Autowired
	private TwitterAccountDAO twitterAccountDAO;
	
	@Override
	public User createUser(String pUsername, String pTweeterUsername) {

		
		final User newUser = new User();
		newUser.setName(pUsername);

		final TweeterAccount tAccount = new TweeterAccount();
		tAccount.setUsername(pTweeterUsername);

		newUser.setAccount(tAccount);
		
		this.twitterAccountDAO.save(tAccount);
		return userDAO.save(newUser);
	}

}
